package jUnitTests;

import static org.junit.Assert.*;

import org.junit.Test;

import java.io.FileNotFoundException;
import java.io.IOException;

import huaabdelmartin.*;

public class DriverTest {

	//create class to run ReadAndStoreInput readAndStoreTaxisCollection() method
	public class Thread1 extends Thread{

		private ReadAndStoreInput rasi;
		public Thread1(ReadAndStoreInput rasi) throws DuplicateDriverIdException, IOException {
			this.rasi = rasi;
			go();
		}

		public void go() throws DuplicateDriverIdException, IOException {
			rasi.readAndStoreTaxisCollection();
		}
	}

	@Test(expected = DuplicateDriverIdException.class)
	public void test() throws DuplicateDriverIdException {

		//I create a new ReadAndStoreInput object then run the readAndStoreTaxisCollection method in two threads at once
		//this should result in DuplicateDriverIDException as t1 will create IDs then t2 will start from 0 and try to create
		//the same ids. The point is to test that DuplicateDriverIdException gets thrown with duplicate ID's

		ReadAndStoreInput rasi = new ReadAndStoreInput();

		Thread1 t1 = null;
		Thread1 t2 = null;
			try {
				t1 = new Thread1(rasi);
				t2 = new Thread1(rasi);
				t1.start();
				t2.start();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
	}
}
